﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Threading;
using System.Threading.Tasks;
using Video.Domain;

namespace Video.Domain
{
    public interface IRepository<TEntity> where TEntity:Entity
    {
        Task<TEntity?> FirstOfDefaultAsync(Expression<Func<TEntity,bool>> predicate,
            CancellationToken cancellationToken=default);
        Task<TEntity> FirstAsync(Expression<Func<TEntity,bool>> predicate,
            CancellationToken cancellationToken = default);
        Task<List<TEntity>> GetLIstAsync(Expression<Func<TEntity,bool>> predicate,
            CancellationToken cancellationToken);
        /// <summary>
        /// 查询数据库是否存在重复
        /// </summary>
        /// <param name="predicate"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        Task<bool> IsExistAsync(Expression<Func<TEntity, bool>> predicate,
            CancellationToken cancellationToken=default);
        Task<IQueryable<TEntity>> GetQueryAsync(Expression<Func<TEntity,bool>> predicate);
        Task<IQueryable<TResult>> GetQueryAsync<TResult>(Expression<Func<TEntity, bool>> predicate,
            Expression<Func<TEntity, TResult>> selector);
        Task<TEntity> InserAsync(TEntity entity,CancellationToken cancellationToken=default);
        Task InserManyAsync(IEnumerable<TEntity> entities,CancellationToken cancellationToken=default);
        Task DeleteAsync(Guid id, CancellationToken cancellationToken=default);
        Task DeleteManyAsync(IEnumerable<Guid> ids,CancellationToken cancellationToken=default);
        Task DeleteAsync(TEntity entity,CancellationToken cancellationToken= default); 
        Task DeleteManyAsync(IEnumerable<TEntity> entities,CancellationToken cancellationToken=default);
        Task<TEntity> UpdateAsync(TEntity entity);
        Task UpdateManyAsync(IEnumerable<TEntity> entities);
    }
}
